package com.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

@Configuration  //声明当前类是一个配置类

// 等同于<context:component-scan base-package="com.itheima.service">，导入其他配置类
@Import({MyBatisConfig.class, JdbcConfig.class})
@ComponentScan("com.service")
@EnableTransactionManagement   //事物管理   等同于<tx:annotation-driven transaction-manager="transactionManager"/>
public class SpringConfig {

    public DataSourceTransactionManager transactionManager(DataSource dataSource){
        DataSourceTransactionManager transactionManager=new DataSourceTransactionManager();

        //配置事物源
        transactionManager.setDataSource(dataSource);
        return transactionManager;
    }

}







